﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using Moq;
using Ninject;
using SportsStore.Domain.Abstract;
using SportsStore.Domain.Concrete;
using SportsStore.Domain.Enities;

namespace SportsStore.WebUI.Infrasture
{
    public class NInjectDependencyResovler:IDependencyResolver
    {
        private readonly IKernel _kernel;

        public NInjectDependencyResovler(IKernel kernel)
        {
            _kernel = kernel;
            AddBinding();
        }

        private void AddBinding()
        {
            //var mock = new Mock<IProductRepository>();
            //mock.Setup(m => m.Products).Returns(new[]
            //    {
            //        new Product {Name = "小米(MI)Air",Category="珠宝",Price=88m,Description = "苗丽珠宝 金丝楠木手串 楠木佛珠念珠手链 男女款手珠 ML1122 18mm"},
            //        new Product {Name = "Apple MacBook Air ",Category="手表",Price=299m,Description = "迪士尼（Disney）防水夜光儿童手表男孩蓝色米奇电子表 多功能运动表男童学生手表80008-1"},
            //        new Product {Name = "Lenovo)IdeaPad310",Category="笔记本",Price=3699m,Description = "联想(Lenovo)IdeaPad310 15.6英寸高性能笔记本（A12-9700P 8G 1T R5 M430 2G显存 正版office2016)白"},
            //        new Product {Name = "灵耀U3000",Category="笔记本",Price =5499m,Description = "灵耀U3000 轻薄机身靓丽外观 "},
            //        new Product {Name = "顽石5700 ",Category="笔记本",Price=4699m,Description = "顽石5700 i7主打性价比 "},
            //        new Product {Name = "惠普(HP)战系列创业本Probook 446 ",Category="笔记本",Price=5499m,Description = "惠普(HP)战系列创业本Probook 446 G3 14英寸商务笔记本(i5-6200U 8G 256G SSD R7 2G独显 FHD 3年上门服务) "},
            //        new Product {Name = "华硕(ASUS) 灵耀 U4000 ",Category="笔记本",Price=5799m,Description = "华硕(ASUS) 灵耀 U4000 14.0英寸超轻薄笔记本电脑(i5-7200U 4G 256GB SSD NV940MX 2G独显 玫瑰金 超窄边框) "},

            //    }
            //);
          
            _kernel.Bind<IProductRepository>().To<ProductRepository>();
            var emailSettings = new EmailSettings
            {
                MailToAddress="order@zjitc.net",
                MailFromAddress = "custome@zjitc.net",
                UseSsl=true,
                UserName="myss",
                Password="pss",
                Server="smtp.zjitc.net",
                Port = 587,
                WriteAsFile=true,
                FileLocation=@"D:\"
            };
            _kernel.Bind<IOrderProcessor>().To<EmailOrderProcessor>().WithConstructorArgument(emailSettings);
            _kernel.Bind<IAuthProvider>().To<FormsAuthProvider>();
        }

        public object GetService(Type serviceType)
        {
            return _kernel.TryGet(serviceType);
        }

        public IEnumerable<object> GetServices(Type serviceType)
        {
            return _kernel.GetAll(serviceType);
        }
    }
}